package com.ldzy.controller;

import com.ldzy.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
public class Mycontroller {
    @RequestMapping("/tolonin")
    public String Lonin(){
        return "/login";
    }
    @RequestMapping("/tomain")
    public String main(){
        return "/main";
    }
    @RequestMapping("/toorderinfo")
    public String orderinfo(){
        return "/orderinfo";
    }
    @RequestMapping(value = "/tolonin",method = RequestMethod.POST)
    public ModelAndView Loninuser(User user, HttpSession httpSession) {
        ModelAndView modelAndView = new ModelAndView();
        if (user.getName().equals("Tom") && user.getPasswod().equals("123"))
        {       modelAndView.setViewName("main");
        httpSession.setAttribute("USER_SESSION", user);
    }
    else {
            modelAndView.setViewName("lonin");
            httpSession.setAttribute("msg",user);
        }
        return modelAndView;
    }
    @RequestMapping("/logout")
    public ModelAndView logout(HttpSession session){
        session.invalidate();
        return "redirect:tolonin";
    }
}
